using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AudioSvc : ILogic
{
    private PERoot mRoot;
    private AudioSource mBgAudio;
    private AudioSource mUIAudio;
    private bool mTurnOnVoice;
    private ResSvc mResSvc;
    public void Init()
    {
        mRoot = PERoot.Instance;
        mResSvc = mRoot.ResService;
        mBgAudio = mRoot.transform.Find("BGAudio").GetComponent<AudioSource>();
        mUIAudio = mRoot.transform.Find("UIAudio").GetComponent<AudioSource>();
        this.Log("AudioSvc.Init...");
    }

    public void Tick()
    {
        if(Input.GetKeyDown(KeyCode.F1))
        {
            mTurnOnVoice = true;
        }
        if(Input.GetKeyDown(KeyCode.F2))
        {
            mTurnOnVoice = false;
        }
    }

    /// <summary>
    /// 播放UI音效
    /// </summary>
    /// <param name="audioName"></param>
    /// <param name="cache"></param>
    public void PlayUIAudio(string audioName,bool cache = true)
    {
        if (mTurnOnVoice)
        {
            AudioClip clip = mResSvc.LoadClip($"{PathDefine.AudioPath}{audioName}", cache);
            mUIAudio.clip = clip;
            mUIAudio.Play();
        }
    }



    public void UnInit()
    {
       this.Log("AudioSvc.UnInit...");
    }
}
